package std.game.objects.views;

import static utils.WordUtils.affixIndefiniteArticle;
import static utils.WordUtils.capitalize;


import org.apache.log4j.Logger;
import org.groovymud.object.Container;
import org.groovymud.object.MudObject;
import org.groovymud.object.alive.Alive;
import org.groovymud.object.registry.InventoryHandler
import std.game.objects.containers.ContainerImpl

public class ContainerMudObjectView<T extends ContainerImpl> extends MudObjectView<T> {

	private transient Logger logger = Logger.getLogger(ContainerMudObjectView.class);
    ContentsHelper contentHelper;

    public void writeLookHeader(Alive looker, T target) {
        super.writeLookBody(looker, target);
        try {
            looker.getTerminalOutput().writeln(capitalize(affixIndefiniteArticle(target)) + " contains:");
        } catch (IOException e) {
            logger.error(e, e);
        }
    }

    public void writeLookBody(Alive looker, T target) {
		InventoryHandler handler = target.getInventoryHandler();
		def dead = handler.getMudObjectsMap().findAll{
            !(it.value instanceof Alive)
        }

		String deadContents = contentHelper.getContentsDescription(dead, looker, false);
		if (dead.size() > 0) {
			try {
				looker.getTerminalOutput().write(deadContents);
			} catch (IOException e) {
				logger.error(e, e);
			}
		}
    }

	@Override
	public void writeLookFooter(Alive looker, T target) {

	}

}
